package book;

public class BookList {
    private static final int DEFAULT_SIZE = 10;
    private Book[] books = new Book[DEFAULT_SIZE ];
    //private Book[] books = new Book[10];
    private int usedSize;//记录当前books数组当中，有多少本书
    //通过构造方法给books这个书架中放书,并通过usedSize来记录书本个数。
    public BookList(){
        books[0] = new Book("三国演义","罗贯中",89,"小说");
        books[1] = new Book("西游记","吴承恩",78,"小说");
        books[2] = new Book("红楼梦","曹雪芹",49,"小说");
        this.usedSize = 3;
    }
    //因为books被private分装了，所以要提供一个get和set方法，
    public Book getBook(int pos){
        return this.books[pos];
        //返回这个books数组中pos下标的元素
    }
    //在Books这个数组的指定的pos位置放一本书
    public void setBook(Book book){
        books[usedSize] = book;//这里写死了，给下标为usedSize的地方添加书，
    }
    public void setBook(int pos,Book book){
        books[pos] = book;//表示给数组下标为pos的地方。放一本书
    }

    public int getUsedSize() {
        return usedSize;
    }

    public void setUsedSize(int usedSize) {
        this.usedSize = usedSize;
    }
}